import 'package:flutter/material.dart';
import 'package:cook_dinner/config/include.dart';
import 'package:flutter/services.dart';

TextField textInput({
  controller, // TextEditingController
  TextInputType keyboardType = TextInputType.text,
  hintText, // 未输入字
  fontSize, // 文字大小
  contentPadding, // 输入框内边距
  int length = 100, // 文本长度
  color = const Color(0xff333333), // 文本
  color1 = const Color(0xff999999),
  bool obscureText = false, // 隐藏输入字
  bool readOnly = false,
  inputFormatters, // 是否输入2位小数 NumLengthInputFormatter()
  customBorder, // 边框和圆角
  textAlign,
  onSubmitted,
  onChanged,
  focusNode,
  cursorColor,
  maxLines, // 允许多行输入
  cursorWidth,
}) {
  return TextField(
    focusNode: focusNode,
    controller: controller,
    autofocus: false,
    //是否自动对焦
    keyboardType: keyboardType,
    // 输入框类型
    cursorWidth: cursorWidth ?? 2.rpx,
    //光标宽度
    cursorColor: cursorColor ?? const Color(0xffcccccc),
    //光标颜色
    obscureText: obscureText,
    readOnly: readOnly,
    cursorRadius: Radius.circular(1.rpx),
    //光标圆角弧度
    maxLines: maxLines,
    style: TextStyle(
      fontSize: fontSize,
      color: color,
      fontWeight: FontWeight.w400,
    ),
    inputFormatters:
        inputFormatters ?? [LengthLimitingTextInputFormatter(length)],
    textAlign: textAlign ?? TextAlign.start,
    decoration: InputDecoration(
      hintText: hintText,
      hintStyle: TextStyle(
        fontSize: fontSize,
        color: color1,
        fontWeight: FontWeight.w400,
      ),
      isCollapsed: true,
      contentPadding: contentPadding,
      border: customBorder ?? defaultBorder,
      enabledBorder: customBorder ?? defaultBorder,
      focusedBorder: customBorder ?? defaultBorder,
      focusedErrorBorder: customBorder ?? defaultBorder,
    ),
  );
}

OutlineInputBorder myOutlineInputBorder([
  color = Colors.transparent,
  width = 0.0,
  radius = 0.0,
]) {
  return OutlineInputBorder(
    borderSide: BorderSide(color: color, width: width),
    borderRadius: BorderRadius.all(Radius.circular(radius)),
  );
}

// 默认边框和圆角样式
InputBorder defaultBorder = OutlineInputBorder(
  borderSide: const BorderSide(color: Colors.transparent, width: 0),
  borderRadius: BorderRadius.circular(0),
);

// 自定义边框和圆角样式
InputBorder customBorder = OutlineInputBorder(
  borderSide: BorderSide(color: Colors.red, width: 1.rpx),
  borderRadius: BorderRadius.circular(10.rpx),
);
